<?php
/**
 * welcome developer.
 * author: liangbo
 * company:tencent suzhou
 * contact:173120209
 * mobile:18550451730
 * Date: 2016-12-18
 * Time: 4:59
 */

class itemController extends Controller
{


    public function index()
    {


        $this->islogin();


    }
    public function ws_test()
    {
        $str=$_SERVER["DOCUMENT_ROOT"].'/tencent/ws.php';
        exec('php '.$str.' &');



    }
    public function index_before()
    {
        $this->islogin();
        $items = (new ItemModel)->find("*");
        $this->api=true;
        echo json_encode($items);
    }

    // 添加记录接口
    public function add_before()
    {   $this->islogin();
        $data=$_POST;
        $count = (new ItemModel)->add($data);
        $this->api=true;
        echo json_encode(array('success'=>$count));
    }

    // 查看记录接口
    public function view_before($id = null)
    {
        $this->islogin();
        $item = (new ItemModel)->find('*',['id'=>$id]);
        $this->api=true;
        echo json_encode($item);

    }

    // 更新记录，测试框架DB记录更新（Update）
    public function update_before($id=null)
    {
        $this->islogin();
        $data = $_POST;
        $count = (new ItemModel)->upp($data,['id'=>$id]);
        $this->api=true;
        echo json_encode(array('success'=>$count));

    }

    // 删除记录，测试框架DB记录删除（Delete）
    public function delete_before()
    {
        $this->islogin();
        $count = (new ItemModel)->del(['id'=>$this->post('id')]);
        $this->api=true;
        echo json_encode(array('success'=>$count));

    }






}